package com.eco.utils;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DateAndStringUtils {
    private static final Logger log = LoggerFactory.getLogger(com.eco.utils.DateAndStringUtils.class);

    public static String getSuffixUrl(Integer id, String createdAt, String times, Integer timestamp) {
        String[] split = StringUtils.split(createdAt, " ");
        String dateStr = split[0].replaceAll("-", "");
        String suffixUrl = dateStr + "/" + dateStr + "/fs_" + times + "_" + id;
        return suffixUrl;
    }

    public static String getSonarSuffixUrl(String createdAt, String times, String fileName) {
        String[] split = StringUtils.split(createdAt, " ");
        String dateStr = split[0].replaceAll("-", "");
        String suffixUrl = dateStr + "/" + dateStr + "/fs_" + times;
        return suffixUrl;
    }

    public static String dateTimeNow2() {
        LocalDateTime dateTime = LocalDateTime.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        return dateTime.format(fmt);
    }

    public static String dateTimeNow() {
        LocalDateTime dateTime = LocalDateTime.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return dateTime.format(fmt);
    }

    public static String dateNow() {
        LocalDateTime dateTime = LocalDateTime.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        return dateTime.format(fmt);
    }

    public static String timestamp2Time(Integer timestampStr) {
        String formats = "HHmmss";
        Long timestamp = Long.valueOf(Long.parseLong("" + timestampStr) * 1000L);
        String date = (new SimpleDateFormat(formats, Locale.CHINA)).format(new Date(timestamp.longValue()));
        return date;
    }
}
